var Nightmare = require('nightmare');       
var nightmare = Nightmare({ show: false, width: 1920, height: 1080 });
let cheerio = require('cheerio')
nightmare
  .goto('https://www.jd.com')
  .type('#key', '魅族手机')
  .click('.search-m button')
  .wait('#J_goodsList')
  .evaluate(function () {
    console.log('eval')
    return document.querySelector('#J_goodsList').innerHTML;
  })
  .end()
  .then(function (html) {
    let $ = cheerio.load(html)
    let $items=$('.gl-item')
    let phones=[]
    $items.each((i,x)=>{
      let name=$(x).find('.p-name').text()
      let price=$(x).find('.p-price i').text()
      phones.push({name,price})
    })
    console.log(phones)
  })
  .catch(function (error) {
    console.error('Search failed:', error);
  });